package 如何优雅的在java中统计代码块耗时;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author vivi20
 * @ClassName AOPtest
 * @Date 2020/3/5 15:13
 * @Vertion 1.0
 */
public class AOPtest {
    // 定义切点，拦截所有满足条件的方法
    @Pointcut("execution(public * com.git.hui.boot.aop.demo.*.*(*))")
    public void point() {
    }

    @Around("point()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        try{
            return joinPoint.proceed();
        } finally {
            System.out.println("cost: " + (System.currentTimeMillis() - start));
        }
    }


}
